<template>
	<!-- 商品组 -->
	<view v-if="dataList.goodsList.data.length" class="diy-sharpGoods" :style="[{'background': background}]">
		<view class="sharp-top dis-flex flex-y-center">
			<view class="sharp-top--left flex-box dis-flex flex-y-center">
				<view class="sharp-modular dis-flex flex-y-center">
					<text class="iconfont icon-miaosha-b"></text>
					<text class="modular-name">限时秒杀</text>
				</view>
				<view class="sharp-active-status">
					<text>{{ dataList.active.sharp_modular_text }}</text>
				</view>
				<!-- 倒计时 -->
				<view v-if="dataList.active.status == ActiveStatusEnum.STATE_BEGIN.value " class="active-count-down">
					<view class="clock dis-flex">
						<view class="clock-time">
							<text>{{ countDownList[0].dynamic.hou }}</text>
						</view>
						<view class="clock-symbol">
							<text>:</text>
						</view>
						<view class="clock-time">
							<text>{{ countDownList[0].dynamic.min }}</text>
						</view>
						<view class="clock-symbol">
							<text>:</text>
						</view>
						<view class="clock-time">
							<text>{{ countDownList[0].dynamic.sec }}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="sharp-top--right">
				<form @submit="_onTargetSharpIndex" report-submit="true">
					<button form-type="submit" class="btn-normal dis-flex">
						<view class="sharp-more dis-flex flex-y-center">
							<text class="sharp-more-text">更多</text>
							<text class="sharp-more-arrow iconfont icon-xiangyoujiantou"></text>
						</view>
					</button>
				</form>
			</view>
		</view>

		<view class="goods-list display__list clear " :class="['column__'+ itemStyle.column ]">
			<view class="goods-item" v-for="(dataItem,index) in dataList.goodsList.data " :key="index" >
				<view  report-submit="true">
					<button class="btn-normal" @tap="_onTargetGoods(dataItem.sharp_goods_id)">
						<view class="goods-item--container">
							<!-- 单列商品 -->
							<block v-if="itemStyle.column == 1 ">
							</block>
							<!-- 两列三列 -->
							<block v-else>
								<!-- 商品图片 -->
								<view class="goods-image">
									<image class="image" mode="aspectFill" :src="dataItem.goods_image "></image>
								</view>
								<view class="detail">
									<!-- 商品标题 -->
									<view v-if="itemStyle.show.goodsName " class="goods-name twolist-hidden">
										{{ dataItem.goods_name }}
									</view>
									<!-- 商品价格 -->
									<view class="detail-price onelist-hidden">
										<text v-if="itemStyle.show.seckillPrice " class="goods-price f-30 col-m">￥{{ dataItem.goods_sku.seckill_price }}</text>
										<text v-if="itemStyle.show.originalPrice && dataItem.goods_sku.original_price > 0 " class="line-price col-9 f-24">￥{{ dataItem.goods_sku.original_price }}</text>
									</view>
								</view>
							</block>
						</view>
					</button>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	const App = getApp();

	// 工具类
	import util from '../../utils/util.js';

	// 倒计时插件
	import CountDown from '../../utils/countdown.js';

	// 枚举类：秒杀活动商品状态
	import ActiveStatusEnum from '../../utils/enum/sharp/GoodsStatus.js';
	export default {
		options: {
			addGlobalClass: true,
		},
		/**
		 * 组件的属性列表
		 * 用于组件自定义设置
		 */
		props: {
			itemIndex: '',
			itemStyle: {},
			params: {},
			dataList: {},
		},
		computed: {
			background() {
				return this.itemStyle.background;
			}
		},
		data() {
			return {
				ActiveStatusEnum, // 秒杀活动商品状态
				countDownList: [], // 倒计时
			}
		},
		/**
		 * 组件生命周期声明对象
		 */
		created: function(options) {
			this._initCountDownData();
		},


		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {

		},
		methods: {
			/**
			 * 跳转商品详情页
			 */
			_onTargetGoods(e) {
				// 记录formid
				// 生成query参数
				let _this = this;
				let query = util.urlEncode({
						active_time_id: _this.dataList.active.active_time_id,
						sharp_goods_id: e,
					});
				// 跳转到商品详情页
				uni.navigateTo({
					url: '../../pages/sharp/goods/index?' + query,
				});
			},

			/**
			 * 更多秒杀
			 */
			_onTargetSharpIndex(e) {
				// 记录formid
				this.saveFormId(e.detail.formId);
				// 跳转到秒杀会场首页
				uni.navigateTo({
					url: '/pages/sharp/index/index',
				});
			},

			/**
			 * 初始化倒计时组件
			 */
			_initCountDownData(data) {
				let _this = this;
				let active = _this.dataList.active;
				if (!active) return false;
				// 记录倒计时的时间

				_this.setData({
					'countDownList.0':{
						date: active.count_down_time,
					}
				});
				
				// 执行倒计时
				CountDown.onSetTimeList(_this, 'countDownList');
			},

		}
	}
</script>

<style>
	.diy-sharpGoods .sharp-top .sharp-modular {
		font-size: 30upx;
		color: #fff;
		background: #fb571d;
		padding: 10upx 30upx 10upx 24upx;
		border-bottom-right-radius: 30upx;
		border-top-right-radius: 30upx;
	}

	.diy-sharpGoods .sharp-top .sharp-modular .modular-name {
		margin-left: 10upx;
	}

	.diy-sharpGoods .sharp-top .sharp-active-status {
		color: #616161;
		font-size: 28upx;
		margin-left: 20upx;
	}

	.diy-sharpGoods .sharp-top .active-count-down {
		font-size: 26upx;
		height: 40upx;
		margin-left: 16upx;
	}

	.diy-sharpGoods .sharp-top .active-count-down .clock-text {
		margin-right: 10upx;
	}

	.diy-sharpGoods .sharp-top .active-count-down .clock-time {
		background: #252525;
		color: #fff;
		padding: 0 6upx;
		line-height: 40upx;
		border-radius: 8upx;
	}

	.diy-sharpGoods .sharp-top .active-count-down .clock-symbol {
		padding: 0 8upx;
	}

	.diy-sharpGoods .sharp-top .sharp-more {
		padding-right: 24upx;
		color: #616161;
		font-size: 28upx;
	}

	.diy-sharpGoods .sharp-top .sharp-more .sharp-more-arrow {
		font-size: 24upx;
	}

	/* 商品组 */

	.diy-sharpGoods .goods-list {
		padding: 4upx;
		box-sizing: border-box;
	}

	.diy-sharpGoods .goods-list .goods-item {
		box-sizing: border-box;
		padding: 6upx;
	}

	.diy-sharpGoods .goods-list.display__list .goods-item {
		float: left;
	}

	.diy-sharpGoods .goods-list.column__2 .goods-item {
		width: 50%;
	}

	.diy-sharpGoods .goods-list.column__3 .goods-item {
		width: 33.33333%;
	}

	.diy-sharpGoods .goods-list .goods-item .goods-image {
		position: relative;
		width: 100%;
		height: 0;
		padding-bottom: 100%;
		overflow: hidden;
		background: #fff;
	}

	.diy-sharpGoods .goods-list .goods-item .goods-image:after {
		content: '';
		display: block;
		margin-top: 100%;
		/* margin 百分比相对父元素宽度计算 */
	}

	.diy-sharpGoods .goods-list .goods-item .goods-image .image {
		position: absolute;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		-o-object-fit: cover;
		object-fit: cover;
	}

	.diy-sharpGoods .goods-list .goods-item .detail {
		padding: 4upx;
		background: #fff;
	}

	.diy-sharpGoods .goods-list .goods-item .detail .goods-name {
		height: 72upx;
		font-size: 28upx;
		line-height: 1.3;
		overflow: hidden;
	}

	.diy-sharpGoods .goods-list .goods-item .detail .detail-price {
		line-height: 40upx;
	}

	.diy-sharpGoods .goods-list .goods-item .detail .goods-price {
		font-size: 30upx;
	}

	.diy-sharpGoods .goods-list .goods-item .detail .line-price {
		margin-left: 8upx;
		font-size: 24upx;
		text-decoration: line-through;
		color: #999;
	}

	.diy-sharpGoods .goods-list .goods-item .detail .selling-point {
		font-size: 24upx;
		color: #f20c59;
	}
</style>
